import { Material, Mesh, Object3D } from 'three';
import { Command } from '../command.js';
import { Editor } from '../editor.js';
/**
 * @param editor Editor
 * @param object THREE.Object3D
 * @param newMaterial THREE.Material
 * @constructor
 */
class SetMaterialCommand extends Command {
	private object:Mesh;
	materialSlot:number;
	oldMaterial:Material;
	newMaterial:Material;
	constructor( editor:Editor, object:Object3D, newMaterial:Material, materialSlot:number ) {

		super( editor );

		this.type = 'SetMaterialCommand';
		this.name = 'New Material';

		this.object = object as Mesh;
		this.materialSlot = materialSlot;

		this.oldMaterial = this.editor.getObjectMaterial( this.object, materialSlot );
		this.newMaterial = newMaterial;

	}

	execute() {

		this.editor.setObjectMaterial( this.object, this.materialSlot, this.newMaterial );
		this.editor.signals.materialChanged.dispatch( this.newMaterial );

	}

	undo() {

		this.editor.setObjectMaterial( this.object, this.materialSlot, this.oldMaterial );
		this.editor.signals.materialChanged.dispatch( this.oldMaterial );

	}


}

export { SetMaterialCommand };
